using DiLu.Expansion.File.Operates.Minio.Configs;
using DiLu.Expansion.File.Operates.Minio.Tools;
using Minio.DataModel.Args;

namespace DiLu.Expansion.File.Operates.Minio;

public static class DeleteMinioFile
{
    /// <summary>
    ///     删除Minio文件
    /// </summary>
    /// <param name="config">删除Minio文件配置</param>
    public static async ValueTask DeleteAsync(this DeleteMinioFileConfig config)
    {
        if (!await config.MinioClient.CheckBucketAsync(config.BucketName)) return;
        if (!await config.MinioClient.FileExistsAsync(config.BucketName, config.FileFullPath)) return;
        await config.MinioClient.RemoveObjectAsync(new RemoveObjectArgs()
            .WithBucket(config.BucketName)
            .WithObject(config.FileFullPath));
    }
}